package com.pepository.dao;

import com.aop.Detach;
import com.model.WordTable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface WordTableRepository extends JpaRepository<WordTable, Long>, JpaSpecificationExecutor {

    List<WordTable> findAllByUserIdOrderByWordInfoId(Long userId, Pageable pageable);

    @Query(value = "select count(id) from word_table where user_id = :userId AND word = :word limit 1", nativeQuery = true)
    int hasByUserIDAndWord(@Param("userId")Long userID, @Param("word") String word);

    @Detach
    @Override
    <S extends WordTable> S save(S entity);
}
